package com.leecode.string;

/**
 * 字符串 全排序
 */
public class StringPermutationMain {
	public static void main(String[] args) {
		permutation(new char[]{'1', '2', '3','5'}, 0);
	}

	/**
	 * 打印全排序
	 */
	public static void permutation(char[] chars, int begin) {
		if (begin == chars.length) {
			System.out.println(new String(chars));
		}
		for (int i = begin; i < chars.length; i++) {
			swap(chars, begin, i);
			permutation(chars, begin + 1);
			swap(chars, begin, i);
		}
	}

	private static void swap(char[] chars, int i, int j) {
		char temp = chars[i];
		chars[i] = chars[j];
		chars[j] = temp;
	}
}

